#if (FEATURE_MODE == 0)
/**
 @file ctc_at_srv6.c

 @date 2019-1-1

 @version v6.0

 Define all APIs of SRv6
*/

/****************************************************************************
 *
* Header Files
*
****************************************************************************/
#include "ctc_error.h"

#include "ctc_at_srv6.h"
#include "sys_usw_srv6.h"
#include "sys_usw_scl_api.h"
#include "sys_usw_common.h"
/****************************************************************************
 *
* Defines and Macros
*
*****************************************************************************/

/****************************************************************************
 *
* Global and Declaration
*
*****************************************************************************/
extern int32
_sys_usw_srv6_init_scl(uint8 lchip, uint8 deinit);

/****************************************************************************
 *
* Function
*
*****************************************************************************/

/**
 @brief Initialize  module
*/
int32
ctc_at_srv6_init(uint8 lchip, ctc_srv6_global_cfg_t* p_global_cfg)
{
    uint8 lchip_start = 0;
    uint8 lchip_end = 0;
    ctc_srv6_global_cfg_t global_cfg;

    FEATURE_SUPPORT_CHECK(CTC_FEATURE_SRV6);
    LCHIP_CHECK(lchip);

    if (NULL == p_global_cfg)
    {
        sal_memset(&global_cfg, 0, sizeof(ctc_srv6_global_cfg_t));
        p_global_cfg = &global_cfg;
        global_cfg.sid_format_bmp = 0x1;
    }
    CTC_AT_FOREACH_LCHIP(lchip_start, lchip_end, 1)
    {
        CTC_ERROR_RETURN(sys_usw_srv6_init(lchip, p_global_cfg));
        if (MCHIP_FEATURE_PP_EN(lchip, CTC_FEATURE_SCL) && lchip != lchip_start &&
            !(CTC_WB_ENABLE(lchip) && CTC_WB_STATUS(lchip) == CTC_WB_STATUS_RELOADING))
        {
            CTC_ERROR_RETURN(_sys_usw_srv6_init_scl(lchip, SRV6_INIT));
        }
    }

    return CTC_E_NONE;
}

int32
ctc_at_srv6_deinit(uint8 lchip)
{
    uint8 lchip_start = 0;
    uint8 lchip_end = 0;

    FEATURE_SUPPORT_CHECK(CTC_FEATURE_SRV6);
    LCHIP_CHECK(lchip);
    CTC_AT_FOREACH_LCHIP(lchip_start, lchip_end, 1)
    {
        CTC_ERROR_RETURN(sys_usw_srv6_deinit(lchip));
    }

    return CTC_E_NONE;
}


int32
ctc_at_srv6_add_my_sid(uint8 lchip, ctc_srv6_sid_t* my_sid)
{
    uint8 lchip_start = 0;
    uint8 lchip_end = 0;
    uint8 all_lchip = 1;
    uint16 pp_bmp = 0;
    int32 ret                      = CTC_E_NONE;

    FEATURE_SUPPORT_CHECK(CTC_FEATURE_SRV6);
    LCHIP_CHECK(lchip);

    pp_bmp = SYS_PP_BMP_MAPPING(my_sid->pp_bmp);
    if(!MCHIP_FEATURE_PP_EN(lchip, CTC_FEATURE_SCL))
    {
        lchip = SYS_PP_BASE(lchip);
        return sys_usw_srv6_add_my_sid(lchip, my_sid);
    }

    CTC_AT_FOREACH_LCHIP(lchip_start, lchip_end, all_lchip)
    {
        if (!CTC_IS_BIT_SET(pp_bmp, lchip-lchip_start))
        {
            continue;
        }
        CTC_FOREACH_ERROR_RETURN(CTC_E_NONE,
                                 ret,
                                 sys_usw_srv6_add_my_sid(lchip, my_sid));
    }

    if (CTC_E_NONE == ret && my_sid->scl_entry_id)
    {
        sys_usw_scl_add_entry_hash_inner(lchip_start, my_sid->scl_entry_id, pp_bmp);
    }

    CTC_AT_FOREACH_ROLLBACK(lchip_start, lchip_end)
    {
        if (!CTC_IS_BIT_SET(pp_bmp, lchip-lchip_start))
        {
            continue;
        }
        sys_usw_srv6_remove_my_sid(lchip, my_sid);
    }

    return ret;
}
int32
ctc_at_srv6_remove_my_sid(uint8 lchip, ctc_srv6_sid_t* my_sid)
{
    uint8 lchip_start = 0;
    uint8 lchip_end = 0;
    uint8 all_lchip = 1;
    uint16 pp_bmp = 0;
    int32 ret                      = CTC_E_NONE;

    FEATURE_SUPPORT_CHECK(CTC_FEATURE_SRV6);
    LCHIP_CHECK(lchip);

    pp_bmp = SYS_PP_BMP_MAPPING(my_sid->pp_bmp);
    if(!MCHIP_FEATURE_PP_EN(lchip, CTC_FEATURE_SCL))
    {
        lchip = SYS_PP_BASE(lchip);
        return sys_usw_srv6_remove_my_sid(lchip, my_sid);
    }

    CTC_AT_FOREACH_LCHIP(lchip_start, lchip_end, all_lchip)
    {
        if (!CTC_IS_BIT_SET(pp_bmp, lchip-lchip_start))
        {
            continue;
        }
        CTC_FOREACH_ERROR_RETURN(CTC_E_NOT_EXIST,
            ret,
            sys_usw_srv6_remove_my_sid(lchip, my_sid));
    }
    return ret;
}
int32
ctc_at_srv6_update_my_sid(uint8 lchip, ctc_srv6_sid_t* my_sid)
{
    uint8 lchip_start = 0;
    uint8 lchip_end = 0;
    uint8 all_lchip = 1;
    uint16 pp_bmp = 0;
	int32 ret = CTC_E_NONE;

    FEATURE_SUPPORT_CHECK(CTC_FEATURE_SRV6);
    LCHIP_CHECK(lchip);

    pp_bmp = SYS_PP_BMP_MAPPING(my_sid->pp_bmp);
    if(!MCHIP_FEATURE_PP_EN(lchip, CTC_FEATURE_SCL))
    {
        lchip = SYS_PP_BASE(lchip);
        return sys_usw_srv6_update_my_sid(lchip, my_sid);
    }

    CTC_AT_FOREACH_LCHIP(lchip_start, lchip_end, all_lchip)
    {
        if (!CTC_IS_BIT_SET(pp_bmp, lchip-lchip_start))
        {
            continue;
        }
        CTC_FOREACH_ERROR_RETURN(CTC_E_NONE,
                                 ret,
                                 sys_usw_srv6_update_my_sid(lchip, my_sid));
    }

    return ret;
}
#endif
